<?

$dataup = 0;
$uprun  = true;

/**
* Check the entry
*
*/
for($iRow = 0; $iRow < $_SESSION["init_num"]; $iRow++){

  /**
  * Check for each master detail
  *
  */
  if($_POST["fromEnt"][$iRow] == '' &&
     $_POST["toEnt"][$iRow]   == '' &&
     $_POST["qtyEnt"][$iRow]  == ''){

    for($iNext = ($iRow + 1); $iNext < $_SESSION["init_num"]; $iNext++ ){

      if($_POST["fromEnt"][$iRow] != '' ||
         $_POST["toEnt"][$iRow]   != '' ||
         $_POST["qtyEnt"][$iRow]  != ''){

        $uprun = false;

        $Misc->usrError("Invalid Entry at : ".($iRow + ARRAY_NUMBER)." ");

        break;
      }
    }

    if($uprun == false){

      /* out of this loop */
      break;
    }
  }else{

    if($_POST["fromEnt"][$iRow] != '' &&
       $_POST["toEnt"][$iRow]   != '' &&
       $_POST["qtyEnt"][$iRow]  != ''){

      $dataup++;
    }else{

      $uprun = false;

      $Misc->usrError("Invalid Entry at : ".($iRow + ARRAY_NUMBER)." ");
    }
  }
}

if($uprun == true && $dataup > 0){

	/**
	* We are good with details
	* continue with the header check
	*
	*/
	if($_POST["modelEnt"]    != '' ){

		//everything is good
		//open confirmation form
		if(!$_POST["confirm"] && !$_POST["back"]){

			require("entry_upload_confirm.php");
		}elseif($_POST["back"]){

			require("entry_restore_me.php");
		}else{

			/**
			* Prepare to upload
			* modify mode is on
			*
			*/
			if($_SESSION["modify_mode"] == "Y" && $_SESSION["jid"] != ''){

				require("upmodifytodb.php");
			}elseif($_SESSION["modify_mode"] != "Y"){ //if modify mode is off

				require("upentrytodb.php");
			}else{

				$Misc->usrError("Unknown Upload Task");
			}
		}
	}else{

		$Misc->usrError("Error: header incompleted");

		require("entry_restore_me.php");
	}
}

if($uprun == false){

	echo "Restoring...\n";
	$restore  = 0;
	$uprun    = 0;
	$dataup   = 0;

	require("entry_restore_me.php");
}
?>